package com.yanqu.road.server.cmd.activity.xingyoushanshui;

import com.yanqu.road.entity.activity.youxing.config.XingYouConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.XingYouShanShuiProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.shanshui.XingYouShanShuiModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.shanshui.XingYouShanShuiMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = XingYouShanShuiProto.ShanShuiExpansionUseReq.class, respMsg = XingYouShanShuiProto.ShanShuiExpansionUseReq.class)
@Cmd(code = Protocol.S_XING_YOU_SHAN_SHUI_EXPANSION_RECYCLE, desc = "扩展图主动回收金页子")
public class ShanShuiExpansionUseCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        XingYouConfig config = XingYouShanShuiMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        XingYouShanShuiProto.ShanShuiExpansionUseReq req = XingYouShanShuiProto.ShanShuiExpansionUseReq.parseFrom(packet.getBytes());
        ret = player.getModule(XingYouShanShuiModule.class).exchangeGold(req.getNum());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_XING_YOU_SHAN_SHUI_EXPANSION_RECYCLE, XingYouShanShuiProto.ShanShuiExpansionUseRsp.newBuilder().setRet(ret));
        }
    }
}
